﻿using System;
using System.Threading;
using System.Threading.Tasks;
using MediatR;
using Solution.Application.Commands.Dtos;
using Solution.Application.Services;

namespace Solution.Application.Commands.Users.Add
{
    public class RequestHandler : IRequestHandler<Request, HandlerResult<bool>>
    {
        private readonly IUserService _userService;

        public RequestHandler(IUserService userService)
        {
            _userService = userService;
        }

        public async Task<HandlerResult<bool>> Handle(Request request, CancellationToken cancellationToken)
        {
            var res = await _userService.CreateUsersAsync(request);

            return new HandlerResult<bool>() { code = ResultCode.StatusOK, data = res };
        }
    }
}